return PNM_FATAL_ERR;
}
- g_print ("File format is %d\n", type);
-
context->type = type;
inbuf->next_byte += 2;
return PNM_SUSPEND;
}
- g_print ("Dimensions are %d x %d\n", w, h);
-
context->width = w;
context->height = h;
inbuf->bytes_left = old_bytes_left;
return PNM_SUSPEND;
}
-
- g_print ("Maximum component value is %d\n", context->maxval);
break;
default:
break;
static gint
pnm_read_ascii_scanline (PnmLoaderContext *context)
{
- guint numpix;
- guint numbytes, offset;
+ guint offset;
gint rc;
guint value, numval, i;
guchar data;
switch (context->type) {
case PNM_FORMAT_PBM:
- mask = 0x80;
- data = 0;
numval = 8;
+ offset = context->output_col/8;
break;
case PNM_FORMAT_PGM:
numval = 1;
+ offset = context->output_col;
break;
case PNM_FORMAT_PPM:
numval = 3;
+ offset = context->output_col*3;
break;
default:
return PNM_FATAL_ERR;
}
- old_next_byte = inbuf->next_byte;
- old_bytes_left = inbuf->bytes_left;
- dptr = context->dptr;
+ dptr = context->dptr + offset;
- for (i=0; i<numval; i++) {
- if ((rc = read_next_number (inbuf, &value))) {
- inbuf->next_byte = old_next_byte;
- inbuf->bytes_left = old_bytes_left;
- return PNM_SUSPEND;
+ while (TRUE) {
+ if (context->type == PNM_FORMAT_PBM) {
+ mask = 0x80;
+ data = 0;
}
- printf ("0x%x ", value);
- fflush (stdout);
-
- switch (context->type) {
- case PNM_FORMAT_PBM:
- if (value)
- data |= mask;
- mask >>= 1;
+
+ old_next_byte = inbuf->next_byte;
+ old_bytes_left = inbuf->bytes_left;
+
+ for (i=0; i<numval; i++) {
+ if ((rc = read_next_number (inbuf, &value))) {
+ inbuf->next_byte = old_next_byte;
+ inbuf->bytes_left = old_bytes_left;
+ return PNM_SUSPEND;
+ }
+ switch (context->type) {
+ case PNM_FORMAT_PBM:
+ if (value)
+ data |= mask;
+ mask >>= 1;
- break;
- case PNM_FORMAT_PGM:
- *dptr++ = (guchar)(255.0*((double)value/(double)context->maxval));
- break;
- case PNM_FORMAT_PPM:
- *dptr++ = (guchar)(255.0*((double)value/(double)context->maxval));
- break;
- default:
- g_warning ("io-pnm.c: Illegal raw pnm type!\n");
- break;
+ break;
+ case PNM_FORMAT_PGM:
+ *dptr++ = (guchar)(255.0*((double)value/(double)context->maxval));
+ break;
+ case PNM_FORMAT_PPM:
+ *dptr++ = (guchar)(255.0*((double)value/(double)context->maxval));
+ break;
+ default:
+ g_warning ("io-pnm.c: Illegal raw pnm type!\n");
+ break;
+ }
}
- }
-
- if (context->type == PNM_FORMAT_PBM)
- *dptr++ = value;
-
- context->output_col++;
- if (context->output_col == context->width) {
- if ( context->type == PNM_FORMAT_PBM_RAW )
- explode_bitmap_into_buf(context);
- else if ( context->type == PNM_FORMAT_PGM_RAW )
- explode_gray_into_buf (context);
- context->output_col = 0;
- context->output_row++;
+ if (context->type == PNM_FORMAT_PBM)
+ *dptr++ = value;
- } else {
- return PNM_SUSPEND;
+ context->output_col++;
+ if (context->output_col == context->width) {
+ if ( context->type == PNM_FORMAT_PBM )
+ explode_bitmap_into_buf(context);
+ else if ( context->type == PNM_FORMAT_PGM )
+ explode_gray_into_buf (context);
+
+ context->output_col = 0;
+ context->output_row++;
+ break;
+ }
+
}
return PNM_OK;
case PNM_FORMAT_PBM:
case PNM_FORMAT_PGM:
case PNM_FORMAT_PPM:
-#if 0
-
rc = pnm_read_ascii_scanline (context);
if (rc == PNM_SUSPEND)
return rc;
break;
-#endif
-
default:
g_print ("Cannot load these image types (yet)\n");
PnmLoaderContext context;
PnmIOBuffer *inbuf;
-
-#if 0
- G_BREAKPOINT();
-#endif
-
/* pretend to be doing progressive loading */
context.updated_func = context.prepared_func = NULL;
context.user_data = NULL;
/* scan until we hit image data */
if (!context.did_prescan) {
-
- g_print ("doing prescan\n");
if (skip_ahead_whitespace (inbuf) == NULL)
continue;
context.width * 3);
if (!context.pixels)
return NULL;
-
- g_print ("prescan complete\n");
}
/* if we got here we're reading image data */